package com.syni.mdd.yhd.common.all.listen.businessReportError;

import com.syni.mdd.yhd.common.all.constants.AuroraPushCode;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.entity.*;
import com.syni.mdd.yhd.common.all.listen.comment.CommentEvent;
import com.syni.mdd.yhd.common.all.service.BmsBusinessService;
import com.syni.mdd.yhd.common.all.service.BmsCommonService;
import com.syni.mdd.yhd.common.all.service.BmsDxNewsService;
import com.syni.mdd.yhd.common.all.service.BmsUserVideoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * @className OrderListener
 * @description TOO
 * @Author cfx
 * @DATE 2019/8/8 15:46
 * @VERSION 1.0
 **/
@Component
public class ReportErrorListener implements ApplicationListener<ReportErrorEvent> {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    BmsUserVideoService bmsUserVideoService;

    @Autowired
    BmsDxNewsService bmsDxNewsService;


    @Autowired
    BmsBusinessService bmsBusinessService;

    @Override
    @Async
    public void onApplicationEvent(ReportErrorEvent reportErrorEvent) {
        BmsReportError bmsReportError = reportErrorEvent.getBmsReportError();
        BmsDxNews bmsDxNews = new BmsDxNews();
        bmsDxNews.setBmsBusinessId(bmsReportError.getBmsBusinessId());
        bmsDxNews.setParentType(Constants.PARENTTYPT_SYS);
        bmsDxNews.setChildType(Constants.PARENTTYPT_SYS_BUSINESS_ERROR);
        bmsDxNews.setContent(bmsReportError.getErrorContent());
        bmsDxNews.setOriginRole(Constants.BUSINESS_ROLE_ID);
        bmsDxNewsService.save(bmsDxNews);
        //加入极光推送
        //String alert = String.format(AuroraPushCode.pushTemplateMap.get(AuroraPushCode.BUSINESS_REPORT_ERROR).getAlert(),bmsDxNews.getContent());
        //BmsCommonService.pushToFront(bmsDxNews,AuroraPushCode.BUSINESS_REPORT_ERROR,alert);
    }
}
